﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using KP_CommonLibrary.KP_CoreUI;
using KEEPER_BRR_13dotNET.BusinessLogic;

namespace KEEPER_BRR_13dotNET.Presentation
{
    public partial class Frm_NhanHoSo2 : KP_CommonLibrary.KP_CoreUI.KP_EditListItem
    {
        DataRow _HoSoHienTai;
        private string _maLoaiHoSo;
        public string MaLoaiHoSo
        {
            get { return _maLoaiHoSo; }
            set
            {
                _maLoaiHoSo = value;
                EnableTab();
            }
        }
        public Frm_NhanHoSo2()
        {
            InitializeComponent();
            //if (!DesignMode)
            //{
            //    BL_KPHoSo blHoSo = new BL_KPHoSo();
            //    _HoSoHienTai = blHoSo.SelectBySttRec("0000000012");
            //    kP_BindingController.Foreach(ForeachControl);

            //}
        }
        void ForeachControl(Control c, BindingProperties b)
        {
            if (string.IsNullOrEmpty(b.PropertyName) || string.IsNullOrEmpty(b.DataMember))
                return;


            SuperTooltipInfo tip = new SuperTooltipInfo(b.DataMember, "", "", null, null, eTooltipColor.Office2003);
            if (_HoSoHienTai != null)
                if (_HoSoHienTai.Table.Columns.Contains(b.DataMember))
                {
                    tip.HeaderText = "Giá trị hiện tại";
                    if (_HoSoHienTai.Table.Columns[b.DataMember].DataType == typeof(DateTime))
                        tip.BodyText = string.Format("{0:dd/MM/yyyy}", _HoSoHienTai[b.DataMember]);
                    else
                        tip.BodyText = _HoSoHienTai[b.DataMember].ToString();
                    tip.CustomSize = new Size(c.Width,0);
                }
            superTooltip1.SetSuperTooltip(c, tip);
        }
        Dictionary<Keys, SuperTabItem> shortcuts = new Dictionary<Keys, SuperTabItem>();
        public override bool DispatchCmdKey(ref Message msg, Keys keyData)
        {
            if (shortcuts.ContainsKey(keyData))
            {
                SupperTab1.SelectedTab = shortcuts[keyData];
                return true;
            }

            return base.DispatchCmdKey(ref msg, keyData);
        }
        public override void AddNew(CurrencyManager cm)
        {

            base.AddNew(cm);
        }
        void SetHotKey()
        {
            int current = 2;
            shortcuts.Clear();
            foreach (SuperTabItem t in SupperTab1.Tabs)
            {
                if (t.Visible)
                {
                    t.Text = t.Tooltip + "(Ctrl+F" + current.ToString() + ")";
                    shortcuts.Add(Keys.Control | (Keys)Enum.Parse(typeof(Keys), "F" + current.ToString()), t);
                    current++;
                }
            }
        }
        void EnableTab()
        {
            sTabCapLai.Visible = true;
            sTabItemGT.Visible = true;
            sTabChamDut.Visible = true;
            sTabItemTN.Visible = true;
            sTabThayDoi.Visible = true;

            sTabItemTV.Visible = true;
            sTabItemNN.Visible = true;
            sTabItemHS.Visible = true;

            //Luon true
            sTabItemGT.Visible = true;
            sTabThongTinHs.Visible = true;
            switch (MaLoaiHoSo)
            {
                case "CL":

                    sTabChamDut.Visible = false;
                    sTabItemTN.Visible = false;
                    sTabThayDoi.Visible = false;
                    sTabItemHS.Visible = false;
                    sTabItemTV.Visible = false;
                    sTabItemNN.Visible = false;
                    break;
                case "TD":
                    sTabChamDut.Visible = false;
                    sTabItemTN.Visible = false;
                    sTabCapLai.Visible = false;
                    break;
                case "CD":
                    sTabCapLai.Visible = false;
                    sTabItemTN.Visible = false;
                    sTabThayDoi.Visible = false;
                    sTabItemHS.Visible = false;
                    sTabItemTV.Visible = false;
                    sTabItemNN.Visible = false;
                    break;
                case "TN":
                    sTabChamDut.Visible = false;
                    sTabCapLai.Visible = false;
                    //sTabItemTN.Visible = false;
                    sTabThayDoi.Visible = false;
                    sTabItemHS.Visible = false;
                    sTabItemTV.Visible = false;
                    sTabItemNN.Visible = false;
                    break;
                case "TDCL":
                    sTabChamDut.Visible = false;
                    sTabItemTN.Visible = false;
                    break;
            }

        }
        public void NhanHoSo(string maLoaiHs,string maHs)
        {
            MaLoaiHoSo = maLoaiHs;
            BL_KPHoSoHKD blHoSoHkd=new BL_KPHoSoHKD();
            BL_KPDmPx blPx = new BL_KPDmPx();
            DataTable tblPx = blPx.SelectByMaHuyen(CauHinh.QuanSuDung());
            DataTable tblData = blHoSoHkd.SelectByMaHS(maHs);
            _HoSoHienTai = tblData.Rows.Count > 0 ? tblData.Rows[0] : null;
            kP_BindingController.Foreach(ForeachControl);
            tomTatHKD1.SetDataSource(tblData,tblPx);
            tomTatHKD2.SetDataSource(tblData, tblPx);
            tomTatHKD3.SetDataSource(tblData, tblPx);
            tomTatHKD4.SetDataSource(tblData, tblPx);

        }

        private void Frm_NhanHoSo2_Load(object sender, EventArgs e)
        {
            SetHotKey();
        }

        private void superTabControlPanel5_Click(object sender, EventArgs e)
        {

        }

        private void kP_TextBox2_TextChanged(object sender, EventArgs e)
        {



        }

        private void groupPanel6_Click(object sender, EventArgs e)
        {


        }

        private void superTabControlPanel10_Click(object sender, EventArgs e)
        {

        }

        private void superTooltip1_BeforeTooltipDisplay(object sender, SuperTooltipEventArgs e)
        {

        }
    }
    [Flags()]
    public enum ShowTab : short
    {
        TamNgung = 0,
        ChamDut = 1,
        ThayDoi = 2,
        CapLai = 4,
        All = 255
    }
}
